//
//  DWChoseDWaterController.swift
//  DWater-Swift
//
//  Created by mac on 2017/4/24.
//  Copyright © 2017年 Dimon.胡亚宾. All rights reserved.
//

import UIKit

class DWChoseDWaterController: BaseViewController, UIGestureRecognizerDelegate
 {
    var onLine : UIView?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        let target = navigationController?.interactivePopGestureRecognizer?.delegate
        let pan = UIPanGestureRecognizer(target: target, action: Selector(("handleNavigationTransition:")))
            pan.delegate = self
            self.view.addGestureRecognizer(pan)
            navigationController?.interactivePopGestureRecognizer?.isEnabled = false
    
        let imageView = UIImageView()
            imageView.image = UIImage.init(named: "login_bg")
            imageView.frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT)
            self.view.addSubview(imageView)
        
            self.onLine = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT))
            self.onLine?.backgroundColor = UIColor.clear
            self.view .addSubview(self.onLine!)
        
        let passline = UIImageView(image: UIImage.init(named: "no_wifi"))
            passline.frame = CGRect(x: self.view.centerX, y:  self.view.centerY - 160, width: 88, height: 95)
            self.onLine?.addSubview(passline)
        
        let label = UILabel(frame:CGRect(x: self.view.centerX - 100, y: self.view.centerY - 55, width:  220, height:  40))
            label.text = "😭哎呦喂，没连接到服务器"
            label.textColor = UIColor.white
            self.onLine?.addSubview(label)
        
        let button = UIButton(type:.custom)
            button.frame = CGRect(x: self.view.centerX - 100, y: self.view.centerY - 55, width: 220, height: 40)
            button.backgroundColor = UIColor.init(hexColor: "3eccce")
            button.setTitle("点击重新连接", for: .normal)
            button.layer.cornerRadius = 5.0
            button.addTarget(self, action:#selector(refashDate))
            onLine?.addSubview(button)
            onLine?.isHidden  = true
            getDateDrivice();

        NotificationCenter.bk_addObserver(self, selector: #selector(getDateDrivice), name: kNotificationRefreshMainData, object: nil)


    }

    func refashDate(){
        self.onLine?.isHidden = true
        self.getDateDrivice()
    }
    
    func getDateDrivice(){
        
        if (DWUserManager.shared.userInfo) != nil {
            
            let  params = DWBaseData.encryptionDataBackDic(dic: nil)
            NetworkRequest.sharedInstance.postAESRequest(urlString: "sensor/checkWpofUserExsits.p", params: params!, success: { (responseObject) in
            print(responseObject)
                
            }, failture: { (error) in
        
        
            })
        }
    }
    

}

extension DWChoseDWaterController{

    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        ///判断是否是根控制器
        if self.childViewControllers.count == 1
        {
            return false
        }
        return true
    }


}


